package org.xzy.es.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

/**
 * @Author xuzhiyang
 * @Date 2023/10/27 16:02
 * @Description
 **/
public class ESTest_Doc_Delete_Batch {

    public static void main(String[] args) throws Exception{

        //创建ES客户端
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("127.0.0.1",9200))
        );

        //批量删除数据
        BulkRequest request = new BulkRequest();

        DeleteRequest deleteRequest = new DeleteRequest().index("user").id("1001");
        request.add(deleteRequest);

        request.add(new DeleteRequest().index("user").id("1002"));
        request.add(new DeleteRequest().index("user").id("1003"));

        BulkResponse response = client.bulk(request, RequestOptions.DEFAULT);

        System.out.println(response.getTook());
        System.out.println(response.getItems());

        client.close();
    }
}
